package cn.itcast.demo.service;

import cn.itcast.demo.mapper.AccountMapper;
import cn.itcast.demo.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 虎哥
 */
@Service
public class AccountService {

    @Autowired
    private AccountMapper accountMapper;

    public Account findById(Long id){
        return accountMapper.findById(id);
    }

    @Transactional
    public void transfer(Long from, Long to, Long amount) {
        // 转入
        accountMapper.updateMoney(to, amount);
        // 转出
        accountMapper.updateMoney(from, -amount);
    }
}
